home *** CD-ROM | disk | FTP | other *** search
/ Network Support Library / RoseWare - Network Support Library.iso / apidev / ndr1.exe / BRETT1.C next >
Text File  |  1993-09-02  |  6KB  |  209 lines

  1. /****************************************************************************
  2. The following code was taken from the Network Developer's Resource, published
  3. by RoseWare.  All contents are Copyright (c) 1993, RoseWare.  All Rights
  4. Reserved.
  5.  
  6. This material is made available as a service for subscribers of the Network
  7. Developer's Resource.  This material is not public domain.  Simply put, if you
  8. are not a subscriber of the Network Developer's Resource, you are using this
  9. material illegally.  
  10.  
  11. Those interested in subscribing should contact RoseWare via:
  12.  
  13. CompuServe:    76711,110
  14. Internet:      76711.110@compuserve.com
  15. Phone:         (703) 799-2509
  16. Fax:           (703) 799-8041
  17. BBS:           (703) 799-2536
  18. US Mail:       P.O. Box 257
  19.                Mount Vernon, VA  22121-0257
  20.  
  21. Also see the file SUBSCRIB.TXT in this ZIP file...
  22.  
  23. Contents:
  24.  
  25. Excerpts from Brett Warthen's "A Window Into NetWare" article in the Premiere
  26. Issue of the Network Developer's Resource.  See text for explanation of the
  27. code.
  28.  
  29. ****************************************************************************/
  30.  
  31. ////////////////////////////////////////////////////////////////////////
  32.  
  33. long LongSwap (long longInt) {
  34.  
  35.    ASM  mov  ax,word ptr longInt
  36.    ASM  mov  bx,word ptr longInt[2]
  37.    ASM  xchg ah,al
  38.    ASM  xchg bh,bl
  39.    ASM  mov  word ptr longInt,bx
  40.    ASM  mov  word ptr longInt[2],ax
  41.  
  42.    return longInt;
  43.  
  44. }
  45.  
  46. ////////////////////////////////////////////////////////////////////////
  47.  
  48. WORD WordSwap (WORD wordInt) {
  49.  
  50.    ASM  mov  ax,wordInt
  51.    ASM  xchg ah,al
  52.    ASM  mov  word ptr wordInt,ax
  53.  
  54.    return wordInt;
  55.  
  56. }
  57.  
  58. ////////////////////////////////////////////////////////////////////////
  59.  
  60.  
  61. ////////////////////////////////////////////////////////////////////////
  62.  
  63. WORD GetConnectionNumber (void) {
  64.  
  65.      WORD i;
  66.  
  67.      ASM  mov  ah,0DCh
  68.      NetWareRequest();
  69.      ASM  cmp  ah,0DCh          // Did high order byte change?
  70.      ASM  jnz  its_big          // Yes...must be a connection # > 255
  71.      ASM  xor  ah,ah            // No...zero out high order byte
  72. its_big:                        //   to return connection # as a word
  73.      ASM  mov  i,ax
  74.  
  75.      return i;
  76.  
  77. }
  78.  
  79. ////////////////////////////////////////////////////////////////////////
  80.  
  81.  
  82. ////////////////////////////////////////////////////////////////////////
  83.  
  84. BYTE NetWareCall (BYTE function_no, LPSTR request_buffer,
  85.  LPSTR reply_buffer) {
  86.  
  87.    BYTE rc;
  88.  
  89.    ASM  push ds                     // Save our segment registers!
  90.    ASM  push es
  91.    ASM  mov  ah,function_no         // Function number in AH
  92.    ASM  lds  si,request_buffer      // DS:SI points to request buffer
  93.    ASM  les  di,reply_buffer        // ES:DI points to reply buffer
  94.    NetWareRequest ();               // call NetWare!
  95.    ASM  pop  es                     // Restore segment registers
  96.    ASM  pop  ds
  97.    ASM  mov  rc,al                  // Return code in AL
  98.  
  99.    return rc;
  100.  
  101. }
  102.  
  103. ////////////////////////////////////////////////////////////////////////
  104.  
  105.  
  106. ////////////////////////////////////////////////////////////////////////
  107.  
  108. BOOL IsBigUserNetWare (void) {
  109.  
  110.    int  rc;
  111.  
  112.    struct {                                      // E3h function 11h
  113.       WORD B1_buffer_length;                     // Get File Server Info
  114.       BYTE B1_subfunction;
  115.    } B_request_buffer;
  116.  
  117.    struct {
  118.      WORD B2_buffer_length;
  119.      char B2_server_name[48];
  120.      BYTE B2_netware_version;
  121.      BYTE B2_netware_subversion;
  122.      WORD B2_max_connections;
  123.      WORD B2_in_use_connections;
  124.      WORD B2_max_volumes;
  125.      BYTE B2_netware_revision_no;
  126.      BYTE B2_SFT_level;
  127.      BYTE B2_TTS_level;
  128.      WORD B2_peak_connections;
  129.      BYTE B2_accounting_version;
  130.      BYTE B2_VAP_version;
  131.      BYTE B2_queuing_version;
  132.      BYTE B2_print_server_version;
  133.      BYTE B2_virtual_console_version;
  134.      BYTE B2_security_restrictions_version;
  135.      BYTE B2_internetwork_bridge_version;
  136.      BYTE B2_reserved[60];
  137.    } B_reply_buffer;
  138.  
  139.    B_request_buffer.B1_buffer_length = sizeof(B_request_buffer) - 2;
  140.    B_request_buffer.B1_subfunction = 0x11;
  141.    B_reply_buffer.B2_buffer_length = sizeof(B_reply_buffer) - 2;
  142.  
  143.    rc = NetWareCall (0xE3, (LPSTR)&B_request_buffer, (LPSTR)&B_reply_buffer);
  144.    if (WordSwap(B_reply_buffer.B2_max_connections) > 255) {
  145.       return TRUE;
  146.    }
  147.    else {
  148.       return FALSE;
  149.    }
  150. }
  151.  
  152. ////////////////////////////////////////////////////////////////////////
  153.  
  154.  
  155. ////////////////////////////////////////////////////////////////////////
  156.  
  157. int GetLoginName (LPSTR loginName) {
  158.  
  159. /* Returns 0 for success, non-zero for failure. */
  160.  
  161.    int  rc;
  162.  
  163.    struct {
  164.       WORD A1_buffer_length;
  165.       BYTE A1_subfunction;
  166.       BYTE A1_connection_number;
  167.    } A_request_buffer;
  168.  
  169.    struct {
  170.       WORD A10001_buffer_length;
  171.       BYTE A10001_subfunction;
  172.       DWORD A10001_connection_number;
  173.    } A1000_request_buffer;
  174.  
  175.    struct {
  176.       WORD A2_buffer_length;
  177.       unsigned long A2_object_id;
  178.       WORD A2_object_type;
  179.       char A2_object_name[48];
  180.       BYTE A2_login_time[8];
  181.    } A_reply_buffer;
  182.  
  183.    A_reply_buffer.A2_buffer_length = sizeof(A_reply_buffer) - 2;
  184.  
  185.    if (IsBigUserNetWare ()) {
  186.       A1000_request_buffer.A10001_buffer_length = sizeof(A1000_request_buffer)
  187. - 2;
  188.       A1000_request_buffer.A10001_subfunction = 0x1C;
  189.       A1000_request_buffer.A10001_connection_number =
  190. (DWORD)GetConnectionNumber();
  191.       rc = NetWareCall (0xE3, (LPSTR)&A1000_request_buffer,
  192. (LPSTR)&A_reply_buffer);
  193.    }
  194.    else {
  195.       A_request_buffer.A1_buffer_length = sizeof(A_request_buffer) - 2;
  196.       A_request_buffer.A1_subfunction = 0x16;
  197.       A_request_buffer.A1_connection_number = (BYTE)GetConnectionNumber();
  198.       rc = NetWareCall (0xE3, (LPSTR)&A_request_buffer,
  199. (LPSTR)&A_reply_buffer);
  200.    }
  201.  
  202.    if (!rc)
  203.       lstrcpy (loginName, A_reply_buffer.A2_object_name);
  204.  
  205.    return rc;
  206. }
  207.  
  208. ////////////////////////////////////////////////////////////////////////
  209.